package com.gulimall.gulimallproduct.web;

import com.gulimall.gulimallproduct.entity.CategoryEntity;
import com.gulimall.gulimallproduct.service.CategoryService;
import com.gulimall.gulimallproduct.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","index.html"})
    public String indexPage(Model model){
        //查出所有一级分类
        List<CategoryEntity> categoryEntityList=categoryService.getLeve1Categorys();
        model.addAttribute("categorys",categoryEntityList);
        return "index";
    }
    @ResponseBody
    @RequestMapping("index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatlogJson() {

        Map<String, List<Catelog2Vo>> map = categoryService.getCatelogJson();
        return map;
    }

    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }
}
